<!DOCTYPE html>
<html lang="en">
<head>
    <title>支出</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-store, must-revalidate">
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT">
    <meta http-equiv="expires" content="-1">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="shortcut icon" href="/dist/img/icon.png" type="image/x-icon">
    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="/dist/plugins/bootstrap/css/bootstrap.min.css">
    <!--字体-->
    <link rel="stylesheet" href="/dist/css/font-awesome.min.css">
    <!--图标-->
    <link rel="stylesheet" href="/dist/css/ionicons.min.css">
    <!--OA主样式-->
    <link rel="stylesheet" href="/dist/css/OA.min.css?t=4a6c1b54">
    <link rel="stylesheet" href="/dist/css/skins/OA-skins.min.css?t=16f1e6f3">
    <script src="https://file.ggxqce.com/web/vue.min.js"></script>
    <style>
        table input, table select {
            border: none;
            outline: none;
        }
        td input{
            color: #2a8cec;
        }
    </style>
</head>
<body>
<section class="content"  id="app"  >
    <div class="oaLoad">
        <div class="loadGif" id="areaProgress"></div>
    </div>
    <input class="pull-left form-control pull-left input-sm" type="text" v-model="time" @focus="showDatePicker($event)" placeholder="请选择时间" style="width: 150px;margin-bottom: 10px;">
    <table class="table table-bordered text-center">
      <thead>
      <tr>
          <th class="tableTitle">银行账户</th>
          <th class="tableTitle">金额</th>
          <th class="tableTitle">支出项目</th>
          <th class="tableTitle"><input type="button" value="+" style="width:20px;margin:2px" title="增加" @click="addTodo()"></th>
      </tr>
      </thead>
        <tbody>
            <tr v-for="(item,i) in list">
                <td>
                    <select style="width:99%;" v-model="item.tkBankCardId">
                        <option v-for="option in bankList" :value="option.id">{{option.bankName}}</option>
                    </select>
                </td>
                <td><input type="number" v-model="item.money"></td>
                <td><input type="text" v-model="item.project"></td>
                <td><input type="button" value="-" style="width:20px;margin:2px" title="减少" @click="removeTodo(i)"></td>
            </tr>
        </tbody>
    </table>
    <div style="height: 30px; line-height: 30px; text-align: center; z-index: 999; padding-top: 5px;"><input type="button" value="保存" class="btn oaBtn btn-sm" style="margin-top: 5px;" @click="save"></div>
    <!-- /.box-body -->
</section>
<!--JQ-->
<script src="https://file.ggxqce.com/web/jquery-2.2.3.min.js"></script>
<!--插件JS-->
<script src="https://file.ggxqce.com/web/bootstrap.min.js"></script>
<!--框架已定义 JS-->
<script src="/dist/js/app_iframe.js?t=602456c3"></script>
<!--oa自定义  JS-->
<script src="/dist/js/oa.js?t=6348cbbc"></script>
<script type="text/javascript" src="/dist/plugins/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="/dist/plugins/lhgdialog/lhgdialog.min.js?self=true"></script>
<script type="text/javascript">
    var api = frameElement.api, W = api.opener;
    var app = new Vue({
        el:'#app',
        data:{
            bankList:[{"bankName":" ","id":" "}],
            list:[
                {"tkBankCardId":"","money":"","project":"","flowDirection":"0","createUserId":getCurrentUser().id,"time":""},
                {"tkBankCardId":"","money":"","project":"","flowDirection":"0","createUserId":getCurrentUser().id,"time":""},
                {"tkBankCardId":"","money":"","project":"","flowDirection":"0","createUserId":getCurrentUser().id,"time":""},
                {"tkBankCardId":"","money":"","project":"","flowDirection":"0","createUserId":getCurrentUser().id,"time":""},
                {"tkBankCardId":"","money":"","project":"","flowDirection":"0","createUserId":getCurrentUser().id,"time":""},
                {"tkBankCardId":"","money":"","project":"","flowDirection":"0","createUserId":getCurrentUser().id,"time":""},
                {"tkBankCardId":"","money":"","project":"","flowDirection":"0","createUserId":getCurrentUser().id,"time":""},
                {"tkBankCardId":"","money":"","project":"","flowDirection":"0","createUserId":getCurrentUser().id,"time":""},
                {"tkBankCardId":"","money":"","project":"","flowDirection":"0","createUserId":getCurrentUser().id,"time":""},
                {"tkBankCardId":"","money":"","project":"","flowDirection":"0","createUserId":getCurrentUser().id,"time":""}
            ],
            companyId:$.wyui.page.urlParams.companyId,
            time:$.wyui.page.urlParams.time,
            isGo:true
        },
        methods:{
            showDatePicker: function (e) {
                var that = this;
                WdatePicker({
                    onpicked: function (dp) {
                        that.time = dp.cal.getNewDateStr();
                        return true;
                    },
                    //dateFmt:'yyyy-MM-dd HH:mm'
                });
                $(e.target).blur();
            },
            removeTodo:function (index) {
                if(this.list.length>1){
                    this.list.splice(index, 1);
                }
            },
            addTodo:function () {
                var that=this;
                var o = new Object();
                o.tkBankCardId = that.bankList[0].id;
                o.money = '';
                o.project = '';
                o.flowDirection='0';
                o,createUserId=getCurrentUser().id;
                o,time=''
                this.list.push(o);
            },
            save:function () {
                var newList=[];
                var that=this;
                for(var i=0;i<this.list.length;i++){
                    if(this.list[i].money!=""){
                        if(this.list[i].money=="0"){
                            alert("金额不能为0");
                            return false;
                        }
                        if(this.list[i].project==""){
                            alert("请填写支出项目！");
                            return false;
                        }
                        that.list[i].newTime=that.time;
                        newList.push(this.list[i]);
                    }
                }
                if(newList.length>0){
                    if(that.isGo){
                        that.isGo=false;
                        $.wyui.postLoadMethod(urlConfig.capital.flow.addFlow, trimRN(newList), function (r) {
                            alert("添加支出流水成功");
                            var $iframe = top.findIframeByName("资金日报表2");
                            $iframe[0].contentWindow.app.getList();
                            var api = frameElement.api, W = api.opener;
                            api.close();
                        },false,true);
                    }

                }else{
                    alert("请填写至少一笔支出流水！");
                }

            }
        },
        mounted:function () {
            var that = this;
            //获取银行卡列表
            $.wyui.postMethod(urlConfig.capital.bankCard.getBankCardList, {"fkCompanyId":that.companyId,useStatus:1}, function (r) {
                that.bankList=r;
                if(r.length!=0){
                    for(var i=0;i<that.list.length;i++){
                        that.list[i].tkBankCardId=that.bankList[0].id;
                        that.list[i].tkOutBankCardId=that.bankList[0].id;
                    }
                }else{
                    alert("请先添加银行账号！")
                    var api = frameElement.api, W = api.opener;
                    api.close();
                }
            });
        }
    });
</script>

</body>
</html>